import json
from tqdm import tqdm

import pandas as pd

'''
ents = []
f = open("entity2id.txt", "r")
lines = f.readlines()
for line in lines:
    ents.append(line.split())
f.close()

rels = []
f = open("relation2id.txt", "r")
lines = f.readlines()
for line in lines:
    rels.append(line.split())
f.close()

# print(ents)
# print(rels)
'''
ents = json.load(open("ent2ids"))
rels = json.load(open("relation2ids"))

triples = []
f = open("path_graph")
lines = f.readlines()

bar = tqdm(lines)
for line in bar:
    triple = line.split()
    t = str(ents[triple[0]]) + "\t" + str(ents[triple[2]]) + "\t" + str(rels[triple[1]]) + "\n"
    triples.append(t)
    bar.set_description()
f.close()
print(triples[0:10])

# for key in f:
#    ents.append(key + "\t" + str(f[key]) + "\n")

f = open("train2id.txt", "w", encoding="utf-8")
f.write(str(len(triples)))
for triple in triples:
    f.write(triple)
f.close()
